package com.wzq.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE","OPTIONS")
                .maxAge(3600);
    }

    /**
     * 添加静态资源映射路径，css、js等都放在classpath下的static中
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * addResourceHandler 指的是对外暴露的访问路径
         * addResourceLocations 指的是文件配置的目录
         */

        //文件上传路径映射
        registry.addResourceHandler("/mimi/upload/**")
                .addResourceLocations("file:C:/mimi/upload/");
        registry.addResourceHandler("/1image/**").addResourceLocations("file:D:\\upload\\image\\");
        registry.addResourceHandler("/image/swiper/**").addResourceLocations("file:D:\\java1234-mall-v3\\swiperImgs\\");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/image/swiper/**").addResourceLocations("classpath:/java1234-mall-v3/wiperImgs/");
//        registry.addResourceHandler("/image/bigType/**").addResourceLocations("classpath:/java1234-mall-v3/bigTypeImgs/");
//        registry.addResourceHandler("/image/product/**").addResourceLocations("classpath:/java1234-mall-v3/productImgs/");
//        registry.addResourceHandler("/image/productSwiperImgs/**").addResourceLocations("classpath:/java1234-mall-v3/productSwiperImgs/");
//        registry.addResourceHandler("/image/productIntroImgs/**").addResourceLocations("classpath:/java1234-mall-v3/productIntroImgs/");
//        registry.addResourceHandler("/image/productParaImgs/**").addResourceLocations("classpath:/java1234-mall-v3/productParaImgs/");
//        System.out.println("1"+"1");
//    }
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/image/swiper/**").addResourceLocations("file:D:\\java1234-mall-v3\\swiperImgs\\");
//        registry.addResourceHandler("/image/bigType/**").addResourceLocations("file:D:\\java1234-mall-v3\\bigTypeImgs\\");
//        registry.addResourceHandler("/image/product/**").addResourceLocations("file:D:\\java1234-mall-v3\\productImgs\\");
//        registry.addResourceHandler("/image/productSwiperImgs/**").addResourceLocations("file:D:\\java1234-mall-v3\\productSwiperImgs\\");
//        registry.addResourceHandler("/image/productIntroImgs/**").addResourceLocations("file:D:\\java1234-mall-v3\\productIntroImgs\\");
//        registry.addResourceHandler("/image/productParaImgs/**").addResourceLocations("file:D:\\java1234-mall-v3\\productParaImgs\\");
//        System.out.println("1"+"1");
//    }

//    @Bean
//    public SysInterceptor sysInterceptor(){
//        return new SysInterceptor();
//    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        String[] patterns=new String[]{"/adminLogin","/product/**","/bigType/**","/user/wxlogin","/weixinpay/**"};
//        registry.addInterceptor(sysInterceptor())
//                .addPathPatterns("/**")
//                .excludePathPatterns(patterns);
//    }

    public static void main(String[] args) {
        for(int i=0;i<10000;i++){
            System.out.println("测试="+i);
        }
    }
}
